/**
 * Created by lwy on 2017/7/5.
 */

//退出
$('#exit').click(function(){
    $.ajax({
        url:'/crm/shiroLongC/exit.json',
        dataType:'json',
        data:{
            token:localStorage.getItem('crmtoken')
        },
        type:'post',
        success:function(data){
            console.log(data.code);
            if(data.code==1){
                localStorage.removeItem('crmtoken');
                window.location.href="/crm/logout"
            }
        }
    })
})

//清理缓存
$('#clearItem').click(function(){
    localStorage.clear();
    window.location.href="/crm/logout"
})

function GetQueryString(name)
{
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null) return  unescape(r[2]); return null;
}

$(function(){
    if(localStorage.getItem('crmphone')==null||localStorage.getItem('crmphone')==undefined||localStorage.getItem('crmphone')==""){

    }else{
        $('#crmphone').html(localStorage.getItem('crmphone'));
    }
})


function ifEmpty(array){
    for(var i=0;i<array.length;i++){
        if(array[i]==""||array[i]==undefined){
            return 0;
        }

    }

}

//登录账号是否包含字母
function checkUser(username)
{
    var user=username;
    var r2 = /[a-zA-Z]/i;
    //如果为空
    if(user==''){
        $('#userTips').show();
        $('#userTips').html('登录账号不能为空');
        return false;
    }
    //如果不包含字母
    if(!r2.test(user))
    {
        $('#userTips').show();
        $('#userTips').html('登录账号必须包含字母');
        return false;
    }

    $('#userTips').hide();
    return true;
}

//检查手机号
function checkMobile(Mobile){
    var sMobile = Mobile;
    if(!(/^1(3|4|5|7|8)\d{9}$/.test(sMobile))){
        $('#phoneTips').show();
        $('#phoneTips').html('手机号格式不正确');
        return false;
    }
    $('#phoneTips').hide();
    return true;
}